﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace IPlayer
{
    /// <summary>
    /// 录像播放状态类型
    /// </summary>
    [Flags]
    public enum PlayerStateEnum
    {
        /// <summary>
        /// 其他类型
        /// </summary>
        Other = 0,
        /// <summary>
        /// 打开状态
        /// </summary>
        Open = 1,
        /// <summary>
        /// 播放状态
        /// </summary>
        Play = 2,
        /// <summary>
        /// 快放
        /// </summary>
        Fast = 4,
        /// <summary>
        /// 慢放
        /// </summary>
        Slow = 8,
        /// <summary>
        /// 一帧一帧播放
        /// </summary>
        OneByOne = 16,
        /// <summary>
        /// 一帧一帧回放
        /// </summary>
        OneByOneBack = 32,
        /// <summary>
        /// 解码播放
        /// </summary>
        Decode = 64
    }


    /// <summary>
    /// 绘图事件参数
    /// </summary>
    public class EventArgsPaint : EventArgs
    {
        /// <summary>
        /// 画笔
        /// </summary>
        public readonly Graphics Graphics;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="graphics">画笔</param>
        public EventArgsPaint(Graphics graphics)
        {
            this.Graphics = graphics;
        }
    }
    /// <summary>
    /// 解码事件参数
    /// </summary>
    public class EventArgsDecode : EventArgs
    {
        /// <summary>
        /// 缓冲区指针
        /// </summary>
        public readonly IntPtr Buffer;

        /// <summary>
        /// 帧图像的宽度
        /// </summary>
        public readonly int Width;

        /// <summary>
        /// 帧图像的高度
        /// </summary>
        public readonly int Height;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="buffer">缓冲区指针</param>
        /// <param name="width">帧图像的宽度</param>
        /// <param name="height">帧图像的高度</param>
        public EventArgsDecode(IntPtr buffer, int width, int height)
        {
            this.Buffer = buffer;
            this.Width = width;
            this.Height = height;
        }
    }
    /// <summary>
    /// 录像文件信息
    /// </summary>
    public struct RecordInfo
    {
        /// <summary>
        /// 起始时间
        /// </summary>
        public readonly DateTime StartTime;

        /// <summary>
        /// 总时长（毫秒）
        /// </summary>
        public readonly TimeSpan TotalTime;

        /// <summary>
        /// 总帧数
        /// </summary>
        public readonly uint TotalFrames;

        /// <summary>
        /// 帧率
        /// </summary>
        public readonly uint FrameRate;

        /// <summary>
        /// 帧大小,即帧图像的宽度和高度
        /// </summary>
        public readonly Size FrameSize;

        /// <summary>
        /// 将录像信息转换成字符串
        /// </summary>
        /// <returns>录像信息字符串</returns>
        public override string ToString()
        {
            throw new Exception();
        }

        /// <summary>
        /// 将字符串转换成录像信息
        /// </summary>
        /// <param name="info">录像信息字符串</param>
        /// <returns>录像信息</returns>
        public static RecordInfo Parse(string info)
        {
            throw new Exception();
        }
    }
    /// <summary>
    ///录像控件的接口，所有的录像控件都遵循这一接口
    /// </summary>
    public interface IPlayerBase
    {
        /// <summary>
        /// 播放结束事件
        /// </summary>
        event EventHandler PlayEnd;

        /// <summary>
        /// 绘图事件
        /// </summary>
        event EventHandler<EventArgsPaint> PlayerPaint;
        
        /// <summary>
        /// 解码事件
        /// </summary>
        event EventHandler<EventArgsDecode> Decode;

        #region 加载时读入
        /// <summary>
        /// 录像区域名称
        /// </summary>
        string Area { get; }

        /// <summary>
        /// 录像设备名称
        /// </summary>
        string Device { get; }

        /// <summary>
        /// 起始时间
        /// </summary>
        DateTime StartTime { get; }

        /// <summary>
        /// 总时长（秒）
        /// </summary>
        TimeSpan TotalTime { get; }

        /// <summary>
        /// 总帧数
        /// </summary>
        uint TotalFrame { get; }

        /// <summary>
        /// 帧率
        /// </summary>
        uint FrameRate { get; }

        /// <summary>
        /// 帧大小,即帧图像的宽度和高度
        /// </summary>
        Size FrameSize { get; }



        #endregion

        #region 实时读取与设置
        /// <summary>
        /// 播放指针相对位置，范围：0-100%
        /// </summary>
        float PlayPosition { get; set; }

        /// <summary>
        /// 当前播放时间，单位：毫秒
        /// </summary>
        TimeSpan PlayedTime { get; set; }

        /// <summary>
        /// 当前帧序号
        /// </summary>
        uint FrameNumber { get; set; }
        #endregion

        #region 状态信息
        /// <summary>
        /// 播放速度，取值区间：[-4,4]，大于0快放，小于0慢放，等于0正常
        /// </summary>
        int Speed { get; }
        #endregion



        /// <summary>
        /// 根据区域名和设备名打开这个设备在参数time时间所录的录像文件
        /// </summary>
        /// <param name="area">区域名</param>
        /// <param name="device">设备名</param>
        /// <param name="time">时间</param>
        /// <returns>true表示成功，false表示失败</returns>
        bool Open(string area, string device, DateTime time);

        /// <summary>
        /// 关闭播放的录像文件
        /// </summary>
        /// <returns>true表示成功，false表示失败</returns>
        bool Close();

        /// <summary>
        /// 播放打开的录像文件
        /// </summary>
        /// <returns>true表示成功，false表示失败</returns>
        bool Play();

        /// <summary>
        /// 停止播放
        /// </summary>
        /// <returns>true表示成功，false表示失败</returns>
        bool Stop();

        /// <summary>
        /// 暂停播放
        /// </summary>
        /// <returns>true表示成功，false表示失败</returns>
        bool Pause();

        /// <summary>
        /// 恢复播放
        /// </summary>
        /// <returns>true表示成功，false表示失败</returns>
        bool Continue();

        /// <summary>
        /// 快放
        /// </summary>
        /// <returns>true表示成功，false表示失败</returns>
        /// 
        bool Fast();

        /// <summary>
        /// 慢放
        /// </summary>
        /// <returns>true表示成功，false表示失败</returns>
        bool Slow();


    }
}
